package cn.myjerry.test.ORM;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * 测试使用Javabean封装一条数据
 * 使用List<Javabean>存储多条数据
 * @author Jerry
 *
 */
public class Demo03 {
	public static void main(String[] args) {
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet res = null;
		List<Employee> list = new ArrayList<>();

		try {
			conn = JDBCUtil.getMysqlConn();
			ps = conn.prepareStatement("SELECT Name,Salary,Age FROM Employee WHERE Id > ?");
			ps.setInt(1, 0);
			res = ps.executeQuery();
			while (res.next()) {
				Employee emp = new Employee(res.getString("Name"), res.getDouble("Salary"), res.getInt("Age"));
				
				list.add(emp);
			}

		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			JDBCUtil.close(res, ps, conn);
		}
		
		for(Employee emp:list) {
			System.out.println(emp.toString());
		}
	}
}
